package com.atguigu.principle;

/**
 * @author LYJ
 * @Description
 * @date 2021 年 09 月 08 日 下午5:41
 */
public class Ocp {
    public static void main(String[] args) {
        GraphicEditor graphicEditor = new GraphicEditor();
        graphicEditor.editor(new Circle());
        graphicEditor.editor(new Rectangle());
    }
}

class GraphicEditor {
    void editor(Shape s) {
        s.draw();
    }
}

class Rectangle extends Shape {
    Rectangle() {
        type = 1;
    }

    @Override
    public void draw() {
        System.out.println("绘画矩形");
    }
}

class Circle extends Shape {

    Circle() {
        type = 2;
    }

    @Override
    public void draw() {
        System.out.println("绘画圆形");
    }
}

abstract class Shape {
    int type;

    public abstract void draw();
}




